/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.wxs.controller;

import cn.webrx.wxs.mapper.GoodsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: wxshop - AdminGoodsController
 * <p>Powered by webrx On 2021-04-19 20:38:14
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 15
 */
@Controller
@RequestMapping("/admin")
public class AdminGoodsController {
    @Autowired
    private GoodsMapper goodsdao;

    @GetMapping("/goods/index")
    @ResponseBody
    public Map<String, Object> index(@RequestParam(name = "type", required = false, defaultValue = "1") int type,int page,int limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        PageHelper.startPage(page, limit);
        PageInfo pi = PageInfo.of(goodsdao.lists(type));
        data.put("list", pi.getList());
        data.put("count", pi.getTotal());
        map.put("msg", "");
        map.put("code", 1);
        map.put("show",0);
        map.put("data", data);
        return map;
    }

    @GetMapping("/goods/lists")
    public String index(Model m) {
        m.addAttribute("sell", 17);
        m.addAttribute("warehouse", 5);
        m.addAttribute("warn", 1);
        m.addAttribute("recycle", 0);
        return "admin/goods/lists";
    }

    @GetMapping("/goods/add")
    public String add() {
        return "admin/goods/add";
    }
}
